package com.java.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class GenericTests {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        ArrayList<String> list=new ArrayList<>();
        list.add("A");
        list.add("B");
        //list.add(100);

        //运行时通过反射技术将100写入到集合list中
        Class<?> aClass = list.getClass();
        Method add = aClass.getDeclaredMethod("add", Object.class);
        add.invoke(list,100);
        System.out.println(list);

    }
}
